<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>鼠标悬浮切图封装</title>
    <link rel="stylesheet" href="base.css">
    <style>
        li{
            float: left;
            margin-top: 20px;
            margin-left: 10px;
            border: 5px solid #fff;
        }
        .active{
            border: 5px solid red;
            
        }
        #bigpicture{
            margin-left: 143px;
            background-image: url(img/brand_goods_1.jpg);
            width: 400px;
            height: 500px;
        }
    </style>
</head>
<body>
    <div id="bigpicture"></div>
    <ul>
        <li class="active"><a href="#">
            <img src="img/brand_goods_1.jpg" id="item1" width="150px" alt="">
        </a></li>
        <li><a href="#">
            <img src="img/brand_goods_2.jpg" id="item2" width="150px" alt="">
        </a></li>
        <li><a href="#">
            <img src="img/brand_goods_3.jpg" id="item3" width="150px" alt="">
        </a></li>
        <li><a href="#">
            <img src="img/brand_goods_4.jpg" id="item4" width="150px" alt="">
        </a></li>
    </ul>
    <script>
        
        function $(id){
            return typeof id === 'string' ? document.getElementById(id):null;
        }
        function changebgcImg(liId,imgSrc){
            $(liId).onmouseover = function(){
                $('bigpicture').style.background = imgSrc;
            }
        }
        changebgcImg('item1','url("img/brand_goods_1.jpg")');
        changebgcImg('item2','url("img/brand_goods_2.jpg")');
        changebgcImg('item3','url("img/brand_goods_3.jpg")');
        changebgcImg('item4','url("img/brand_goods_4.jpg")');
    </script>
</body>
</html>